home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / archiver / lha211sr.zip / LHASRC.EXE / SFX_.ASM < prev    next >
Assembly Source File  |  1991-03-03  |  24KB  |  1,303 lines

  1. ;***********************************************
  2. ;    sfx_.asm -- self-extract module
  3. ;***********************************************
  4.  
  5. page    0, 128
  6. include    amscls.inc
  7.  
  8. $_init GEN
  9.  
  10. _TEXT    segment byte public 'CODE'
  11. _TEXT    ends
  12.  
  13. DGROUP    group    _BSS
  14.         assume    cs:_TEXT, ds:DGROUP
  15.  
  16. CRC16            equ        0a001h
  17. BufSiz            equ        04000h
  18.  
  19. NC            =        (200h - 2)
  20. NP            =        14
  21. NT            =        19
  22. NPT            =        080h
  23.  
  24. CBIT        =        9
  25. PBIT        =        4
  26. TBIT        =        5
  27.  
  28. DSIZ        =        2000h
  29. DSIZ2        =        DSIZ * 2
  30.  
  31. LzHead    struc
  32.         HeadSiz db        ?
  33.         HeadChk db        ?
  34.         HeadID    db        3 dup (?)
  35.         Method    db        ?
  36.                 db        ?
  37.         PacSiz    dw        2 dup (?)
  38.         OrgSiz    dw        2 dup (?)
  39.         FTime    dw        ?
  40.         FDate    dw        ?
  41.         FAttr    dw        ?
  42.         FnLen    db        ?
  43.         Fname    db        80h dup (?)
  44. LzHead    ends
  45.  
  46. _BSS    segment para public 'BSS'
  47.         public    crctbl
  48.         public    cpyhdr, infile, outfile
  49.         public    inpptr, inpbuf, text_
  50.         public    curcrc, orgcrc
  51.         public    myname
  52.         public    pathname, fnnext, swchar
  53.         public    blocksize_
  54.  
  55. text_            db        DSIZ2 dup (?)
  56. inpbuf            db        BufSiz dup (?)
  57. crctbl            dw        100h dup (?)
  58. cpyhdr            LzHead    1 dup (<?>)
  59. inpptr            dw        1 dup (?)
  60. infile            dw        1 dup (?)
  61. outfile            dw        1 dup (?)
  62. orgcrc            dw        1 dup (?)
  63. curcrc            dw        1 dup (?)
  64. blocksize_        dw        1 dup (?)
  65.  
  66. len_cnt            dw        17 dup (?)
  67. start            dw        17 dup (?)
  68. weight            dw        17 dup (?)
  69.  
  70. public    len_cnt
  71. public    start
  72. public    weight
  73.  
  74.  
  75. left_            dw        2 * NC - 1 dup (?)
  76. right_            dw        2 * NC - 1 dup (?)
  77.  
  78. c_table_        dw        4096 dup (?)
  79. pt_table_        dw        256 dup (?)
  80. c_len_            db        NC dup (?)
  81. pt_len_            db        NPT dup (?)
  82.  
  83. public    left_
  84. public    right_
  85. public    c_table_
  86. public    pt_table_
  87. public    c_len_
  88. public    pt_len_
  89.  
  90. bitbuf_            dw        1 dup (?)
  91. subbitbuf_        db        1 dup (?)
  92. bitcount_        db        1 dup (?)
  93.  
  94. myname            db        80h dup (?)
  95. pathname        db        80h dup (?)
  96. fnnext            dw        1 dup (?)
  97. fnptr            dw        1 dup (?)
  98. swchar            db        1 dup (?)
  99. endBBS            label    byte
  100. _BSS            ends
  101.  
  102. _TEXT    segment byte public 'CODE'
  103.         assume    cs:_TEXT
  104.  
  105.         org        0100h
  106.  
  107.         public    start, main
  108.         public    BSSseg
  109.         public    #cright, crlf, space
  110.         public    absent, #myself, broken, extend
  111.         public    #subver
  112.  
  113. top:
  114.         jmp        main
  115.  
  116. BSSseg    =        (#endofcode - top + 10fh) / 10h
  117. mes_yn    equ        space - 1
  118. space    db        ' ', 0
  119. #cright    db        "LHA's SFX 2.11"
  120. #subver    db        "L (c) Yoshi, 1991"
  121. crlf    db        13, 10, 0
  122. absent    db        'Rename to '
  123. #myself    db        'FILENAME.EXT', 0
  124. overwt    db        'Overwrite ', 0
  125. yesno    db        '[Y/N] ', 0
  126. broken    db        'Broken file ', 0
  127. write    db        'Write', 0
  128. header    db        'Header', 0
  129. crcmes    db        'CRC'
  130. error    db        ' Error', 0
  131. auto    db        1, '!'
  132. autoflg db        '.' shr 1
  133.         db        'BAT'
  134. extend    db        0ffh
  135. attrib    db        0
  136.  
  137. envseg    =        002ch
  138. cmdcnt    =        0080h
  139. cmdline =        0081h
  140.  
  141. ;-----------------------------------------------
  142. ;        âüâCâôâïü[â`âô
  143. ;-----------------------------------------------
  144. main:
  145.         cld
  146.         mov        sp, offset top
  147.         mov        ax, cs
  148.         add        ax, BSSseg
  149.         mov        es, ax
  150.  
  151.         assume    es:DGROUP
  152.  
  153.         call    @getopt
  154.  
  155.         public    #getopt
  156. #getopt:
  157.         mov        bx, offset #cright
  158.         call    mesout
  159.         push    es
  160.         pop        ds
  161.  
  162.         assume    ds:DGROUP
  163. ;-----------------------------------------------
  164. ;        Get my name
  165. ;-----------------------------------------------
  166.         mov        ah, 30h
  167.         int        21h                                ; get DOS ver.
  168.         mov        bx, ax
  169.         push    ds
  170.         $_if <cmp al, 3>, AE                    ; if DOS ver. >= 3.00
  171.             mov        es, ss:[envseg]
  172.             xor        ax, ax
  173.             mov        di, ax
  174.             mov        cx, -1
  175.             $_do
  176.                 repne    scasb
  177.                 scasb
  178.             $_until , E
  179.             inc        ax
  180.             scasw
  181.             push    es
  182.             pop        ds
  183.             mov        dx, di
  184.             $_if , E
  185.                 call    openme
  186.             $_endif
  187.         $_endif
  188. brknenv:
  189.         push    cs
  190.         pop        ds
  191.         mov        dx, offset #myself
  192.         call    openme
  193.         $_if <cmp bl, 2>, E                    ; if DOS ver. = 2
  194.             mov        ax, ss:[0002h]            ;  get pathname from trash
  195.             sub        ax, 38h                    ;  of command.com
  196.             mov        ds, ax
  197.             mov        dx, 0009h
  198.             call    openme
  199.         $_endif
  200.         mov        bx, offset absent
  201.         jmp        errout1
  202. openme:
  203.         mov        ax, 3d00h
  204.         int        21h                                ; Open Myself
  205.         $_if , C
  206.             ret
  207.         $_endif
  208.         pop        cx                                ; pop old ip
  209.  
  210.         pop        ds
  211.         mov        infile, ax
  212.  
  213.         mov        bx, ax
  214.         xor        cx, cx
  215.  
  216. ifndef COM
  217.     exehdr    =        20h
  218. else
  219.     exehdr    =        0h
  220. endif
  221.  
  222.         mov        dx, (#endofcode - top) + exehdr
  223.  
  224.         public    #seeksize
  225. #seeksize:
  226.  
  227.         mov        ax, 4200h
  228.         int        21h                                ; Move a File Pointer
  229.         $_if , C
  230. brokenerr:
  231.             mov        bx, offset broken        ; Broken file
  232.             jmp        errout
  233.         $_endif
  234.         push    ds
  235.         pop        es
  236. ;---------------------------------------
  237. ;        make CRC table
  238. ;---------------------------------------
  239.         mov        di, offset crctbl
  240.         xor        dx, dx
  241.         $_do
  242.             mov        ax, dx
  243.             mov        cx, 8
  244.             $_do
  245.                 $_if <shr ax, 1>, C
  246.                     xor        ax, CRC16
  247.                 $_endif
  248.             $_until <LOOP>
  249.             stosw
  250.         $_until <inc dl>, Z
  251. ;---------------------------------------
  252.  
  253.         public mainloop
  254. mainloop:
  255.         $_while <TRUE>
  256.  
  257.             call    crlfout
  258. ; Get Header ---------------------------
  259.             mov        si, offset DGROUP:cpyhdr.HeadSiz
  260.             mov        dx, si
  261.             mov        cx, 1
  262.             mov        [si], ch
  263.             mov        bx, infile
  264.             mov        ah, 3fh
  265.             int        21h                        ; Read header size
  266.             dec        cx                        ; cx = 0
  267.             add        cl, [si]
  268.             $_if , Z
  269.                 jmp        exit
  270.             $_endif
  271.             inc        dx
  272.             inc        si
  273.  
  274.             inc        cx
  275.             mov        ah, 3fh
  276.             int        21h                        ; Read header
  277.  
  278. ; Test Header Sum ----------------------
  279.             lodsb
  280.             push    si                    ; cpyhdr.HeadID
  281.             dec        cx
  282.             dec        si
  283.             $_do
  284.                 inc        si
  285.                 sub        al, [si]
  286.             $_until <LOOP>
  287.             jne        errhdr
  288.             pop        si
  289.  
  290. ; Test Header ID -----------------------
  291.             lodsw
  292.             $_if <cmp ax, 'l-'>, NE, OR
  293.                 lodsw
  294.                 xchg    al, ah
  295.                 sub        ax, 'h0'
  296.                 mov        bp, ax                ; bp = method
  297.             $_c                 , NZ, AND
  298.             $_c  <sub ax, 0004h>, NE, AND
  299.             $_c  <dec ax>       , NE, OR
  300.                 lodsb
  301.             $_c  <sub al, '-'>, NZ
  302. errhdr:
  303.                 mov        bx, offset header
  304.                 jmp        errout
  305.             $_endif
  306.  
  307. ; Get original CRC ---------------------
  308.             mov        bx, offset DGROUP:cpyhdr.Fname
  309.             mov        dx, bx
  310.             mov        cx, [bx - 1]
  311.             add        bl, cl                ; doesn't carry up
  312.  
  313.             xchg    ax, [bx]            ; ax = 0, [bx] = CRC
  314.             mov        orgcrc, ax
  315.  
  316. ; Test Special File ? ------------------
  317.             mov        fnptr, dx
  318.             cmp        cx, 2101h                ; 01h, '!'
  319.             $_if , E
  320.                 mov        ax, 1
  321.                 jmp        mn7
  322.             $_endif
  323.  
  324.             call    @extended
  325.  
  326.         public    #extended
  327. #extended:
  328.  
  329.  
  330. ; Display File name --------------------
  331.             mov        word ptr [bx], 0 * 256 + ' '
  332.             mov        bx, dx
  333.             call    disp                    ; output file name
  334.             mov        byte ptr [bx - 1], 0
  335.  
  336.             jcxz    mn9                        ; !.BAT ?
  337.  
  338. ; Check Existence of File --------------
  339.             mov        ax, 4300h                ; get file attr
  340.             int        21h                        ;    (for MS-DOS 3.3)
  341.             jc        mn1
  342.  
  343. ; Overwrite ? --------------------------
  344.             mov        bx, offset overwt    ; prompt
  345.             call    mesout
  346.             call    getyn
  347.             je        mn1
  348.  
  349. ; Skip to next File --------------------
  350.             mov        dx, DGROUP:cpyhdr.PacSiz        ; skip file
  351.             mov        cx, DGROUP:cpyhdr.PacSiz + 2
  352.  
  353.             mov        bx, infile
  354.             mov        ax, 4201h
  355.             int        21h                    ; Move a File Pointer
  356.             jmp        mn6
  357. mn9:
  358.             mov        cs:autoflg, 0dh
  359.  
  360. ; Create a New File --------------------
  361. mn1:
  362.             mov        cx, 0020h
  363.             mov        ah, 3ch
  364.             int        21h                    ; Create a File
  365.             $_if , C
  366.                 jmp        errwrite
  367.             $_endif
  368.  
  369. ; Decode -------------------------------
  370. mn7:
  371.             mov        outfile, ax
  372.  
  373.             xor        ax, ax
  374.             mov        curcrc, ax
  375.             dec        ax
  376.             mov        inpptr, ax
  377.  
  378.             push    dx
  379.             $_if <or bp, bp>, NZ
  380.                 call    decode
  381.             $_else
  382.                 call    copyall
  383.             $_endif
  384.             pop        si
  385.  
  386. ; Set Time-Stamp -----------------------
  387.             mov        bx, outfile
  388.             cmp        bx, 1                    ; file '!' ?
  389.             je        mn8
  390.  
  391.             mov        dx, DGROUP:cpyhdr.FDate
  392.             mov        cx, DGROUP:cpyhdr.FTime
  393.             mov        ax, 5701h                ; set date
  394.             int        21h
  395.             call    close
  396.  
  397. ; Check CRC ----------------------------
  398.             mov        ax, curcrc
  399.             cmp        ax, orgcrc
  400.             jne        errcrc
  401.  
  402.             call    @setattr
  403.  
  404. public    #setattr
  405. #setattr:
  406.  
  407.  
  408.             jmp        mn6
  409. mn8:
  410.             call    getyn
  411.             jne        exit1
  412. mn6:
  413.         $_enddo
  414.         mov        bx, infile
  415.         call    close
  416.  
  417.         public    exit
  418. exit:
  419.         call    @autoexec
  420.  
  421.         public    #autoexec
  422. #autoexec:
  423. exit1:
  424.         xor        al, al
  425. exit2:
  426.         mov        ah, 4ch
  427.         int        21h
  428.  
  429. ;-----------------------------------------------
  430. ;        âGâëü[Åêù¥
  431. ;-----------------------------------------------
  432.         public    errhdr, errwrite, errout
  433. errcrc:
  434.         call    unlink
  435.         mov        bx, offset crcmes
  436.         jmp        short errout1
  437.  
  438. errwrite:
  439.         mov        bx, outfile
  440.         call    close
  441.         call    unlink
  442.         mov        bx, offset write
  443.  
  444. errout:
  445.         call    mesout
  446.         mov        bx, offset error
  447. errout1:
  448.         call    mesout
  449.         mov        al, 1
  450.         jmp        exit2
  451.  
  452.